package com.example.anydo.util.pub_util;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;

import com.example.anydo.R;

public class LoadingPlayer {


    private final Context context;
    private final Animation animation;
    private AlertDialog dialog;

    public LoadingPlayer(Context context){
        this.context = context;

        animation = AnimationUtils.loadAnimation(context, R.anim.loading);
        animation.setInterpolator(new Interpolator() {
            @Override
            public float getInterpolation(float input) {
                return input;
            }
        });
    }

    public void loading(String msg){
        LayoutInflater inflater = LayoutInflater.from(context);
        View showView = inflater.inflate(R.layout.layout_loading, null);

        AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.dialog);
        builder.setView(showView);//加载进去
        builder.setCancelable(false);

        dialog = builder.create();
        dialog.show();

        ImageView imageView = showView.findViewById(R.id.iv_loading);
        TextView tv_msg = showView.findViewById(R.id.tv_msg);
        tv_msg.setText(msg);
        imageView.startAnimation(animation);
    }

    public void dismiss(){
        dialog.dismiss();
    }

}
